package com.example.goods.controller;

import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Enumeration;
import java.util.Map;

/**
 * @author: mtl
 * @Date: 2022/1/19 14:27
 * @Description:
 */
@RestController
@RequestMapping("/demo")
public class demo {

    @ResponseBody
    @RequestMapping("test1")
    public String test1(HttpServletRequest request) {

        show(request);
        return "123123123";
    }

    @ResponseBody
    @RequestMapping("test2")
    public String test2(HttpServletRequest request){
        show(request);
        return "123123123";
    }

    public static void show(HttpServletRequest request){
        Enumeration<String> headerNames = request.getHeaderNames();
        while (headerNames.hasMoreElements()) {
            String name = headerNames.nextElement();
            //根据名称获取请求头的值
            String value = request.getHeader(name);
            System.out.println(name+"---"+value);
        }
    }


}
